package com.chensf.studydemo.guide.design

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chensf.studydemo.R
import kotlinx.android.synthetic.main.activity_snap_helper_demo.*

class SnapHelperDemo : AppCompatActivity(){
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_snap_helper_demo)
        recyclerView.layoutManager = GridLayoutManager(this,4)
        recyclerView.adapter = MyAdapter()
    }


    class MyAdapter:RecyclerView.Adapter<MyViewHolder>(){
        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
           return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.view_grid_item_1,parent,false))
        }

        override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
            holder.text.text = "哈哈$position"
        }

        override fun getItemCount(): Int {
            return 50
        }

    }

    class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){
        val text:TextView = itemView.findViewById(R.id.textView)
    }
}